%ifdef win32
	%define callAssemblerFunction _callAssemblerFunction
	%define malloc _malloc
	%define free _free
%endif

; ------------- FUNCIONES EXPORTADAS ---------------------
global callAssemblerFunction		; Variant callAssemblerFunction(void *func, void *args, int argsSize, double *decimalResult)
; --------------------------------------------------------

; ------------- FUNCIONES EXTERNAS -----------------------
extern malloc		; void *malloc(int bytes);
extern free			; void free(void *memoria);
; --------------------------------------------------------

section .data

; ------------- VARIABLES GLOBALES -----------------------

; --------------------------------------------------------

section .text

; --------------------------------------------------------
; Variant callAssemblerFunction(void *func, void *args, int argsSize, double *decimalResult)

callAssemblerFunction:
	push ebp
	mov ebp, esp

	;xor ecx, ecx
	;IDIV ecx
	
	finit ; inicializamos la fpu por las dudas, sino tira overflow
	
	mov ecx, [ebp + 16]	; ecx = argsSize
	shr ecx, 2			; ecx = argsSize / 4
	mov eax, [ebp + 12]	; eax = args
	
.loop:
	mov edx, [eax]		; edx = args[i]
	push edx
	add eax, 4
	loop .loop	

	mov eax, [ebp + 8]	; eax = func

	call eax			; call func
	add esp, [ebp + 16]	; esp += argsSize
	
	mov ecx, [ebp + 20]	; ecx = decimalResult
	fst qword [ecx]		; *decimalResult = st0
	
	pop ebp
	ret
